

import { HTTP } from "@/tools";
import { StandardQuery, StandardEntity, StandardPagingResult, StandardResponse } from "./standard";

export interface DictTypeBaseInfo {
  id?: string,
  code: string,
  name: string,
  sort: number,
  remark: string,
}
export interface DictTypeListItem extends DictTypeBaseInfo, StandardEntity { }
export async function getDictTypeListByPageing(params: IdctPagingQueryParam) {
  return HTTP.post<StandardResponse<StandardPagingResult<DictTypeListItem>>>('/sysDictType/page', params)
}

/**
 * 删除字典类型
 * @param  id
 * @returns 
 */
export async function DictTypeDelete(id: string) {
  return HTTP.post('/sysDictType/delete', { id })
}

/**
 * 保存字典类型
 * @param params 
 * @returns 
 */
export async function SaveDictTypeInfo(params: DictTypeBaseInfo) {
  return HTTP.post(`/sysDictType/${params.id ? 'edit' : 'add'}`, params)
}




/**
 * 字典详情
 */
export interface DictDetailInfo extends Omit<DictTypeBaseInfo, 'id' | 'name'> {
  // 类别code
  dictTypeCode: string,
  // 类别id
  typeId: number | string,
  // 字典的name:概念类似于类别的name
  value: string,
  id?: string|number,
}


export type IDictQueryParam = Partial<DictDetailInfo> & Partial<StandardQuery>
// 分页查询字典查询参数
export type IdctPagingQueryParam = Partial<{ name: string, code: string }> & Partial<StandardQuery>
// 字典查询结果项
export interface IDiceQueryResult extends DictDetailInfo, Partial<StandardEntity> { }
// 给出字典值,主要用于选择使用
export async function getsysDictData(params: IDictQueryParam) {
  return HTTP.post<StandardResponse<IDiceQueryResult[]>>('/sysDictData/list', params)
}

/**
 * 删除字典
 * @param id 
 * @returns 
 */
export async function DictDelte(id: number | string) {
  return HTTP.post('/sysDictData/delete', { id })
}


/**
 * 保存字典
 * @param  params
 * @returns 
 */
export async function DictInfoSave(params: DictDetailInfo) {
  const { id } = params
  return HTTP.post(`/sysDictData/${id ? 'edit' : 'add'}`, params)
}
